<?php
function dt_default_action() {
	add_action( 'dt_area_under_menu', 'dt_bredcrumbs' );
}

function dt_bredcrumbs() {
    if( function_exists( 'dimox_breadcrumbs' ) ) {
        
        $wrap_before = '<div id="breadcrumbs_bg"><div id="breadcrumbs_m"><div id="breadcrumbs">';
        $wrap_after = '</div></div></div>';
        
        $args = array(
            'before_wrapper'    => $wrap_before,
            'after_wrapper'     => $wrap_after,
            'delimiter'         => '',
            'before'            => '<li>',
            'after'             => '</li>',
            'show_trail'        => of_get_option( 'breadcrumbs_checkbox', true )
        );
        dimox_breadcrumbs( $args );
        return true;
    }
    return false;
}

function dt_home_action() {
	add_action( 'dt_area_under_menu', 'dt_slider' );
}

function dt_slider() {
    global $post, $wpdb, $wp_query, $paged;
    $thumb = '';
    
    if( $paged > 1 ) {
        return dt_bredcrumbs();
    }
    
    $args = array(
        'post_type'	        => 'dt_slider',
        'posts_per_page'    => -1
    );
    
    $dt_slider = new Wp_Query( $args );
?>

    
    <div id="pxs_container" class="pxs_container">

        <div class="pxs_bg">
            <div class="pxs_bg1"></div>
            <div class="pxs_bg2"></div>
            <div class="pxs_bg3"></div>
        </div>
        
        <?php if( $dt_slider->have_posts() ):?>
        
        <div class="pxs_loading"><span></span></div>
        <div class="pxs_slider_wrapper">
            <ul class="pxs_slider">
                <?php
                while( $dt_slider->have_posts() ):
                    $dt_slider->the_post();
                    
                    $defaults = array(
                        'link'      => '',
                        'hide_desc' => false
                    );
                    $slide_opts = get_post_meta( get_the_ID(), 'dt_slider-post', true );
                    $slide_opts = wp_parse_args( $slide_opts, $defaults );
                    
                    $s_img = dt_get_thumbnail(
                        array(
                            'post_id'	=> get_the_ID(),
                            'width'		=> 150,
                            'height'	=> 150,
                            'upscale'   => true
                        )
                    );
                    
                    $thumb .= sprintf(
                        '<li><div><img src="%1$s" alt="%2$s"/><i></i></div></li>',
                        $s_img['thumnail_img'],
                        esc_attr(get_the_title())
                    );
                    
                    $b_img = dt_get_thumbnail(
                        array(
                            'post_id'	=> get_the_ID(),
                            'width'		=> 922,
                            'height'	=> 362,
                            'upscale'   => true
                        )
                    );
                ?>
                <li>
                    <div class="holder">
                        <img src="<?php echo $b_img['thumnail_img']; ?>" <?php echo $b_img['size_str']; ?> alt="<?php echo esc_attr(get_the_title()); ?>" />
                        <div class="mask"></div>
                        <?php if( !$slide_opts['hide_desc'] ): ?>
                        <div class="desc_outer">
                           <div class="desc">
                                <div class="desc_bg">
                                    <h4><?php the_title(); ?></h4>
                                    <div class="desc_text">
                                        <?php echo get_the_excerpt(); ?>
                                    </div>
                                    
                                    <?php if( !empty($slide_opts['link']) ): ?>
                                    
                                    <a class="desc_details" href="<?php echo esc_url($slide_opts['link']); ?>"><?php _e( 'Details', LANGUAGE_ZONE ); ?></a>
                                    
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                        <?php endif; ?>
                    </div>
                </li>
                <?php endwhile; ?>
            </ul>
            
            <?php if( count($dt_slider->posts) > 1 ): ?>
            <div class="pxs_thumbnails_holder">
                <span class="pxs_prev"></span>
                <ul class="pxs_thumbnails">
                    <?php echo $thumb; ?>
                </ul>
                <span class="pxs_next"></span>
            </div>
            <?php else: ?>
            <script type="text/javascript">
                slider_auto = 0;
            </script>
            <div class="pxs_thumbnails_holder" style="display: none !important;">
                <ul class="pxs_thumbnails">
                    <?php echo $thumb; ?>
                </ul>
            </div>
            <?php endif; ?>
            
        </div>
        
        <?php else: ?>
            
            <div class="pxs_loading">
                <?php _e( 'Slider empty...', LANGUAGE_ZONE ); ?>
            </div>
            
        <?php endif; ?>
        
        <?php
        if( of_get_option( 'decor_corner_checkbox', true ) ) {
            
            $img = sprintf(
                '<div id="best_lable"><img src="%s" width="%d" height="%d"/></div>',
                get_template_directory_uri().'/images/pink/slider/lable.png',
                168,
                166
            );
            
            if( of_get_option( 'custom_decor_corner_checkbox', false ) ) {
            
                $img = of_get_option( 'custom_decor_corner_uploader', '' );
                if( ( strpos( $img, '.png') || strpos( $img, '.jpg') || strpos( $img, '.gif') ) ){
                    $img_size = getimagesize( $img );
                    if( !$img_size ) {
                        $img = '';
                    }else {
                        $img = sprintf(
                            '<div id="best_lable"><img src="%s" %s/></div>',
                            $img,
                            $img_size[3]
                        );
                    }
                }                
            }
            
            echo $img;
        }
        ?>

    
    </div>
    
<?php
    wp_reset_query();
    return true;
}

// custom tab ----------------------------------------------------------------------------------
// gallery media library
// filter: dt_media_upload_tab_filter
function dt_media_tab() {
    $errors = array();

    if ( !empty($_POST) ) {
        $return = media_upload_form_handler();

        if ( is_string($return) )
            return $return;
        if ( is_array($return) )
            $errors = $return;
    }

    wp_enqueue_style( 'media' );
    wp_enqueue_script('admin-gallery');
    
    return wp_iframe( 'dt_media_form', $errors );
}
add_action( 'media_upload_dtmedia', 'dt_media_tab' );